package org.jeecg.modules.power.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.app.v1.util.Const;
import org.jeecg.modules.power.shop.entity.YlTransferShopRecords;
import org.jeecg.modules.power.shop.mapper.YlTransferShopRecordsMapper;
import org.jeecg.modules.power.shop.service.IYlTransferShopRecordsService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Locale;

/**
 * @Description: 门店转移记录表
 * @Author: jeecg-boot
 * @Date:   2024-07-13
 * @Version: V1.0
 */
@Service
@RequiredArgsConstructor
public class YlTransferShopRecordsServiceImpl extends ServiceImpl<YlTransferShopRecordsMapper, YlTransferShopRecords> implements IYlTransferShopRecordsService {

    /**
     * 查询bd下的门店转移记录
     * @param bd
     */
    public List<YlTransferShopRecords> getRecords(String bd,String shopId,String beginTime,String endTime){
        QueryWrapper<YlTransferShopRecords> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("shop_id",shopId)
                .orderByDesc("create_time");

        if(oConvertUtils.isNotEmpty(beginTime)) {
            String btime = String.format("%sT%s", beginTime, Const.TIME_000000);
            queryWrapper.ge(oConvertUtils.isNotEmpty(beginTime),"create_time",btime);
        }
        if(oConvertUtils.isNotEmpty(endTime)) {
            /**
             * 时间相等返回空，需要取当前时间
             */
            String lowerTime = DateUtils.compareTimeBackLower(endTime, LocalDate.now().toString());
            String etime = oConvertUtils.isEmpty(lowerTime) ? LocalDateTime.now().toString() : String.format("%sT%s", lowerTime, Const.TIME_235959);
            queryWrapper.le(oConvertUtils.isNotEmpty(endTime),"create_time",etime);
        }

        return this.list(queryWrapper);
    }

    @Override
    public IPage<YlTransferShopRecords> recordsList(Page<YlTransferShopRecords> page, String rname, String tname,String transferStatus) {
        return baseMapper.recordsList(page, rname, tname,transferStatus);
    }

}
